//
//  Runner.m
//  server
//
//  Created by Jan Nase on 23.12.11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Runner.h"


@implementation Runner

@synthesize checkpointID, carrying_points, caught, caughtBy, allowed_to_bring_home;

-(id)initWithName:(NSString *)pName andClientID: (NSString*)pClientID andTeamID: (NSString*)pTeamID{
	self = [super initWithName:pName andClientID:pClientID andTeamID:pTeamID];
	if(self){
		carrying_points = 0;
		caught = false;
        caughtBy = [[NSMutableArray alloc] initWithCapacity:3];
        allowed_to_bring_home = false;            
	}
	return self;
}

-(id)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
      if( [aDecoder decodeObjectForKey:@"checkpointID"] != nil ) {
        checkpointID = [[NSString alloc] initWithString:[aDecoder decodeObjectForKey:@"checkpointID"]];
      } else {
        checkpointID = nil;
      }
      carrying_points = [aDecoder decodeIntForKey:@"carrying_points"];		
      caught = [aDecoder decodeBoolForKey:@"caught"];
      allowed_to_bring_home = [aDecoder decodeBoolForKey:@"allowed_to_bring_home"];        
      caughtBy = [[aDecoder decodeObjectForKey:@"caughtBy"] retain];
    }
    return self;
}

-(void)encodeWithCoder:(NSCoder *)aCoder{
	[super encodeWithCoder:aCoder];	
    [aCoder encodeObject:checkpointID forKey:@"checkpointID"];
    [aCoder encodeInt:carrying_points forKey:@"carrying_points"];	
    [aCoder encodeBool:caught forKey:@"caught"];	
    [aCoder encodeBool:allowed_to_bring_home forKey:@"allowed_to_bring_home"];	    
    [aCoder encodeObject:caughtBy forKey:@"caughtBy"];	
}

-(void)dealloc{
    [checkpointID release];
    [caughtBy release];
	[super dealloc];
}

-(NSString*) description {
  return [NSString stringWithFormat:@"RUNNER: %@ @ (%f, %f)", name, last_position_lat, last_position_long];
}

@end
